<?php

namespace App\Services\Sms;

use Illuminate\Contracts\Container\BindingResolutionException;
use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Exceptions\InvalidArgumentException;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;

/**
 * 手机短信
 * @package App\Services\Sms
 */
class SmsService
{
    /**
     * 手机短信
     * @param mixed $mobile
     * @param mixed $data
     * @return array
     * @throws BindingResolutionException
     * @throws InvalidArgumentException
     * @throws NoGatewayAvailableException
     */
    public function send($mobile, $data)
    {
        $easySms = new EasySms($this->config());
        return $easySms->send($mobile, $data);
    }

    /**
     * 服务配置项
     * @return (float|array)[]
     * @throws BindingResolutionException
     */
    protected function config()
    {
        return [
            // HTTP 请求的超时时间（秒）
            'timeout' => 5.0,
            // 默认发送配置
            'default' => [
                // 网关调用策略，默认：顺序调用
                'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,
                // 默认可用的发送网关
                'gateways' => [
                    'aliyun',
                ],
            ],
            // 可用的网关配置
            'gateways' => [
                'errorlog' => [
                    'file' => '/tmp/easy-sms.log',
                ],
                'aliyun' => [
                    'access_key_id' => config('site.aliyun.accessKeyId'),
                    'access_key_secret' =>  config('site.aliyun.accessKeySecret'),
                    'sign_name' => config('site.sms.aliyun.sign'),
                ],

            ],
        ];
    }
}
